<template>
  <div class="exception-container">
    <div class="img-wrapper">
      <img :src="statusImage" />
    </div>
    <div class="title">
      <div>{{ statusTip }}</div>
      <div class="margin-top-lg">
        <el-button type="primary" size="small" @click="backHome"> 返回首页 </el-button>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { computed } from "vue";
import image_404 from "@images/img_404.png";
import image_403 from "@images/img_403.png";
import image_500 from "@images/img_500.png";

import {useRouter} from "vue-router"

// export default defineComponent({
//   name: "ExceptionStatus",
  const props =defineProps({
    status: {
      type: [Number, String],
      default: "404",
    },
  });
    const router = useRouter();

    // 获取图片
    const statusImage = computed ({
      get(){
        if (props.status.toString() === "404") {
          return image_404;
        } else if (props.status.toString() === "403") {
          return image_403;
        } else {
           return image_500;
        }
      },
      set(){}
    });
    // 提示信息
    const statusTip = computed({
      get() {
        if (props.status.toString() === "404") {
          return "您访问的页面不存在";
        } else if (props.status.toString() === "403") {
          return "您没有权限访问该页面";
        } else {
          return "您访问的页面出错啦";
        }
      },
      set() { }
    });


    // 返回首页
    function backHome(){
      router.replace({
        name: 'home'
      })
    };
</script>

<style scoped lang="scss">
.exception-container {
    text-align: center;
    height: 100%;
.img-wrapper {
    width: 80%;
    margin: 0 auto;
    & > img {
    width: 100%;
    }
}
.title {
    margin-top: -50px;
}
}
</style>
